package com.example.bookmall.mapper;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.bookmall.entity.order.OrderVo;
import com.example.bookmall.entity.order.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface OrderMapper extends BaseMapper<Orders> {


    /**
     * 连表分页查询用户订单
     */
    @Select("SELECT o.* , " +
            " u.user_id as userId, u.username as username   " +
            "FROM orders o " +
            "LEFT JOIN user u  ON u.user_id = o.user_id " +
            "${ew.customSqlSegment}")
    Page<OrderVo> selectUserOrderPage(Page<OrderVo> page, QueryWrapper<Orders> queryWrapper);

    // 根据订单id查询订单
    @Select("SELECT * FROM orders WHERE order_id = #{orderId}")
    Orders selectByOrderId(String orderId);
}
